"""
数据模型模块
包含所有数据库实体模型
"""

# 基础导入
from .audiobook import (
    AudioBook,
    AudioBookChapter,
    AudioBookProgress,
    AudioBookReview,
    AudioBookTag,
    AudioBookStatus
)
from .voice_profile import (
    VoiceProfile,
    VoicePreset,
    VoiceProfileReview,
    VoiceUsageLog,
    VoiceFavorite,
    VoiceGender,
    VoiceEngine
)
from .audio_stream import (
    AudioStream,
    StreamQualityEvent,
    StreamConnectionLog,
    StreamBuffer,
    StreamSession,
    StreamStatus,
    StreamType
)
from .user import (
    User,
    UserSession,
    UserAPIKey,
    UserActivity,
    UserSettings,
    UserRole,
    UserStatus
)
from .task import (
    Task,
    TaskLog,
    TaskSchedule,
    TaskQueue,
    TaskDependency,
    TaskStatus,
    TaskPriority,
    TaskType
)

# 导出所有模型
__all__ = [
    # 有声读物模型
    'AudioBook',
    'AudioBookChapter',
    'AudioBookProgress',
    'AudioBookReview',
    'AudioBookTag',
    'AudioBookStatus',
    
    # 语音配置模型
    'VoiceProfile',
    'VoicePreset',
    'VoiceProfileReview',
    'VoiceUsageLog',
    'VoiceFavorite',
    'VoiceGender',
    'VoiceEngine',
    
    # 音频流模型
    'AudioStream',
    'StreamQualityEvent',
    'StreamConnectionLog',
    'StreamBuffer',
    'StreamSession',
    'StreamStatus',
    'StreamType',
    
    # 用户模型
    'User',
    'UserSession',
    'UserAPIKey',
    'UserActivity',
    'UserSettings',
    'UserRole',
    'UserStatus',
    
    # 任务模型
    'Task',
    'TaskLog',
    'TaskSchedule',
    'TaskQueue',
    'TaskDependency',
    'TaskStatus',
    'TaskPriority',
    'TaskType'
]

# 版本信息
__version__ = '1.0.0'
__author__ = 'Offline Language Player Team'


def get_all_models():
    """获取所有模型类"""
    return [
        # 有声读物
        AudioBook,
        AudioBookChapter,
        AudioBookProgress,
        AudioBookReview,
        AudioBookTag,
        
        # 语音配置
        VoiceProfile,
        VoicePreset,
        VoiceProfileReview,
        VoiceUsageLog,
        VoiceFavorite,
        
        # 音频流
        AudioStream,
        StreamQualityEvent,
        StreamConnectionLog,
        StreamBuffer,
        StreamSession,
        
        # 用户
        User,
        UserSession,
        UserAPIKey,
        UserActivity,
        UserSettings,
        
        # 任务
        Task,
        TaskLog,
        TaskSchedule,
        TaskQueue,
        TaskDependency
    ]


def get_model_by_name(name: str):
    """根据名称获取模型类"""
    model_map = {
        'AudioBook': AudioBook,
        'AudioBookChapter': AudioBookChapter,
        'AudioBookProgress': AudioBookProgress,
        'AudioBookReview': AudioBookReview,
        'AudioBookTag': AudioBookTag,
        'VoiceProfile': VoiceProfile,
        'VoicePreset': VoicePreset,
        'VoiceProfileReview': VoiceProfileReview,
        'VoiceUsageLog': VoiceUsageLog,
        'VoiceFavorite': VoiceFavorite,
        'AudioStream': AudioStream,
        'StreamQualityEvent': StreamQualityEvent,
        'StreamConnectionLog': StreamConnectionLog,
        'StreamBuffer': StreamBuffer,
        'StreamSession': StreamSession,
        'User': User,
        'UserSession': UserSession,
        'UserAPIKey': UserAPIKey,
        'UserActivity': UserActivity,
        'UserSettings': UserSettings,
        'Task': Task,
        'TaskLog': TaskLog,
        'TaskSchedule': TaskSchedule,
        'TaskQueue': TaskQueue,
        'TaskDependency': TaskDependency
    }
    
    return model_map.get(name)


def get_model_table_names():
    """获取所有表名"""
    models = get_all_models()
    return [model.__tablename__ for model in models]


def get_model_info():
    """获取模型信息"""
    models = get_all_models()
    info = {}
    
    for model in models:
        info[model.__name__] = {
            'table_name': model.__tablename__,
            'columns': [col.name for col in model.__table__.columns],
            'relationships': [rel.key for rel in model.__mapper__.relationships],
            'docstring': model.__doc__ or ''
        }
    
    return info
